package com.rabbiter.oes.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rabbiter.oes.entity.Student;
import com.rabbiter.oes.entity.Teacher;
import com.rabbiter.oes.mapper.StudentMapper;
import com.rabbiter.oes.service.StudentService;
import com.rabbiter.oes.utils.PasswordEncryptionExample;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public IPage<Student> findPage( Page<Student> page, String name, String grade, String tel, Integer collegeId, Integer majorId, String clazz) {
        name = ("@".equals(name) ? "" : name);
        grade = ("@".equals(grade) ? "" : grade);
        tel = ("@".equals(tel) ? "" : tel);
        clazz = ("@".equals(clazz) ? "" : clazz);
        return baseMapper.findPage(page, name, grade, tel, collegeId, majorId, clazz);
    }

    @Override
    public List<Student> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public Long findCountByAcc(String acc) {
        return baseMapper.findCountByAcc(acc);
    }

    @Override
    public Student findById(Integer id) {
        return baseMapper.findById(id);
    }

    @Override
    public int deleteById(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int update(Student student) {
        return baseMapper.updateById(student);
    }

    @Override
    public int updatePwd(Student student) {
        return baseMapper.updatePwd(student);
    }

    @Override
    public int add(Student student) {
        // 添加学生之前先对密码加密处理
        student.setPwd(PasswordEncryptionExample.encrypted(student.getPwd()));
        return baseMapper.insert(student);
    }
}
